package scalab.utils

/**
* This object contains utilities to deal with hexadecimal strings
*/
object Hexadecimal{

	/**
	* Converts an array of bytes into an hexadecimal string.
	*/
	def fromByteArray(bytes: Array[Byte]): String = {
		if(bytes eq null) ""
		else{
			val out: StringBuffer = new StringBuffer(bytes.length << 1)
			val digits: Array[Char] = 
				Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f')

			for(b <- bytes){
				out.append(digits(((b & 0xF0) >>> 4).toInt))
				out.append(digits((b & 0x0F).toInt))
			}
			new String(out)
		}
	}
}
